﻿using System;
using System.Collections.Generic;
using System.Data;
using YXYLCommon;

namespace Entity
{
    /// <summary>
    /// 报表
    /// </summary>
    public class BAOBIAODY : BaseModel
    {
        public BAOBIAODY()
        {
            this.ID=DbInt.InitNull();
            this.I_BAOBIAOID = DbInt.InitNull();
            this.I_FUID = DbInt.InitNull();
            this.I_BAOBIAOLX = DbInt.InitNull();
        }

        public DbInt ID { get; set; }

        public DbInt I_BAOBIAOID { get; set; }

        public DbInt I_FUID { get; set; }

        public DbInt I_BAOBIAOLX { get; set; }

        public string S_BAOBIAOMC { get; set; }

        public string S_MUBANMC { get; set; }

        public string S_CHAXUNGC { get; set; }

        public string S_SHENGCHENGGC { get; set; }

        public string S_TESHUCL { get; set; }

        public string S_QUANXIAND { get; set; }

        public string S_SHENGCHENGQXD { get; set; }

        public string S_MIAOSHU { get; set; }

        public string S_GONGSHIMS { get; set; }

        public DbDateTime D_SHENGXIAOSJ { get; set; }

        public DbInt I_SUOSHUXT { get; set; }

        public string S_CAOZUOR { get; set; }

        public DbDateTime D_CAOZUOSJ { get; set; }

        public DbInt RoleID { get; set; }

        public DbInt UserID { get; set; }

        public override BaseModel ToObject(System.Data.DataRow row)
        {
            this.IsExists = true;
            this.ID = DbInt.Parse(row["ID"]);
            this.I_BAOBIAOID = DbInt.Parse(row["I_BAOBIAOID"]);
            this.I_FUID = DbInt.Parse(row["I_FUID"]);
            this.I_BAOBIAOLX = DbInt.Parse(row["I_BAOBIAOLX"]);
            this.S_BAOBIAOMC = Convert.ToString(row["S_BAOBIAOMC"]);
            this.S_MUBANMC = Convert.ToString(row["S_MUBANMC"]);
            this.S_CHAXUNGC = Convert.ToString(row["S_CHAXUNGC"]);
            this.S_SHENGCHENGGC = Convert.ToString(row["S_SHENGCHENGGC"]);
            this.S_TESHUCL = Convert.ToString(row["S_TESHUCL"]);
            this.S_QUANXIAND = Convert.ToString(row["S_QUANXIAND"]);
            this.S_SHENGCHENGQXD = Convert.ToString(row["S_SHENGCHENGQXD"]);
            this.S_MIAOSHU = Convert.ToString(row["S_MIAOSHU"]);
            this.S_GONGSHIMS = Convert.ToString(row["S_GONGSHIMS"]);
            this.D_SHENGXIAOSJ = DbDateTime.Parse(row["D_SHENGXIAOSJ"]);
            this.S_CAOZUOR = Convert.ToString(row["S_CAOZUOR"]);
            this.D_CAOZUOSJ = DbDateTime.Parse(row["D_CAOZUOSJ"]);
            this.I_SUOSHUXT = DbInt.Parse(row["I_SUOSHUXT"]);
            this.UserID = DbInt.Parse(row.Table.Columns.Contains("UserID") ? row["UserID"] : null);
            this.RoleID = DbInt.Parse(row.Table.Columns.Contains("RoleID") ? row["RoleID"] : null);
            return this;
        }
    }

   
    public class DALBaoBiaoDY:BaseDAL
    {
        public DALBaoBiaoDY()
        {
           
        }
        protected override void fillSaveProc(BaseModel model)
        {
            BAOBIAODY obj = (BAOBIAODY)model;
        }

       /// <summary>
       /// 获取报表列表
       /// </summary>
       /// <param name="wtype">2:地下水 1:地表水 0:自来水</param>
       /// <param name="type">1:报表 2:票据打印 null:所有</param>
        public List<BAOBIAODY> GetAll(int wtype,int type)
        {
            dbProc.Init("P_YSBB_HUOQULB");
            dbProc.AddParameter("V_WTYPE", wtype);
            dbProc.AddParameter("V_TYPE", type);
            dbProc.AddOracleCursor();
            return CommonService.Ini().GetList<BAOBIAODY>(dbProc);
        }

        /// <summary>
        ///根据报表ID获取报表信息
        /// </summary>
        public BAOBIAODY GetByBaoBiaoID(int baobiaoid)
        {
            dbProc.Init("P_YSBB_HUOQUBBXX");
            dbProc.AddParameter("V_BAOBIAOID",baobiaoid);
            dbProc.AddOracleCursor();
            return CommonService.Ini().GetObject<BAOBIAODY>(dbProc);
        }

        /// <summary>
        ///根据报表ID获取报表信息
        /// </summary>
        public List<BAOBIAODY> FenLeiGetAll()
        {
            dbProc.Init("P_YSBB_HUOQUBBFL");
            dbProc.AddOracleCursor();
            return CommonService.Ini().GetList<BAOBIAODY>(dbProc);
        }

        public DbCmdResult Save(BAOBIAODY obj)
        {
            dbProc.Init("P_YSBB_SAVE");
            dbProc.AddParameter("V_I_BAOBIAOID",obj.I_BAOBIAOID.DvalueDBParameter);
            dbProc.AddParameter("V_I_FUID", obj.I_FUID.DvalueDBParameter);
            dbProc.AddParameter("V_I_BAOBIAOLX", obj.I_BAOBIAOLX.DvalueDBParameter);
            dbProc.AddParameter("V_S_BAOBIAOMC", obj.S_BAOBIAOMC);
            dbProc.AddParameter("V_S_MUBANMC", obj.S_MUBANMC);
            dbProc.AddParameter("V_S_CHAXUNGC", obj.S_CHAXUNGC);
            dbProc.AddParameter("V_S_SHENGCHENGGC", obj.S_SHENGCHENGGC);
            dbProc.AddParameter("V_S_TESHUCL", obj.S_TESHUCL);
            dbProc.AddParameter("V_S_QUANXIAND", obj.S_QUANXIAND);
            dbProc.AddParameter("V_S_SHENGCHENGQXD", obj.S_SHENGCHENGQXD);
            dbProc.AddParameter("V_S_MIAOSHU", obj.S_MIAOSHU);
            dbProc.AddParameter("V_S_GONGSHIMS", obj.S_GONGSHIMS);
            dbProc.AddParameter("V_D_SHENGXIAOSJ", obj.D_SHENGXIAOSJ.TimeDBParameter);
            dbProc.AddParameter("V_S_CAOZUOR", obj.S_CAOZUOR);
            dbProc.AddParameter("V_I_SUOSHUXT", obj.I_SUOSHUXT.DvalueDBParameter);
            dbProc.AddParameter("V_OPERATE", obj.Operate.ToString());
            return CommonService.Ini().ExcuteProcOracle(dbProc);
        }

        public DbCmdResult Del(int biaobiaoid)
        {
            dbProc.Init("P_YSBB_DELETE");
            dbProc.AddParameter("V_BAOBIAOID", biaobiaoid);
            return CommonService.Ini().ExcuteProcOracle(dbProc);
        }

        /// <summary>
        /// 根据输入参数获取报表数据源
        /// </summary>
        /// <param name="csList">参数列表</param>
        /// <returns>查询结果</returns>
        public DataSet GetDataByCS(BAOBIAODY obj,List<BaoBiaoCS> csList)
        {
            dbProc.Init(obj.S_CHAXUNGC);
            foreach (var item in csList)
            {
                dbProc.AddParameter(item.S_CANSHU,item.GetDbValue(),item.GetDbType());
            }
            //dbProc.AddOracleReturnParam();
            //dbProc.AddOracleCursor();
            return CommonService.Ini().GetOracleDataSet(dbProc);
        }

        public List<BAOBIAODY> GetRoleByRoleID(string RoleID, int authorityType, int wtype, int type)
        {
            dbProc.Init("P_GetRoleByRoleID");
            dbProc.AddParameter("V_ROLEID", RoleID);
            dbProc.AddParameter("V_WTYPE", wtype);
            dbProc.AddParameter("V_TYPE", type);
            dbProc.AddParameter("AUTHORITYTYPE", authorityType);
            dbProc.AddOracleCursor();
            return CommonService.Ini().GetList<BAOBIAODY>(dbProc);
        }

        public DbCmdResult SaveReportRole(int RoleID, int authorityType, string s, int wtype)
        {
            dbProc.Init("P_SaveReportRole");
            dbProc.AddParameter("V_ROLEID", RoleID);
            dbProc.AddParameter("ARRREPORTID", s);
            dbProc.AddParameter("AUTHORITYTYPE", authorityType);
            dbProc.AddParameter("V_WTYPE", wtype);
           
            return CommonService.Ini().ExcuteProcOracle(dbProc);
        }

        public DataTable loadReportRole(int RoleID, int authorityType)
        {
            dbProc.Init("P_loadReportRole");
            dbProc.AddParameter("V_ROLEID", RoleID);
            dbProc.AddParameter("AUTHORITYTYPE", authorityType);
            dbProc.AddOracleCursor();
            return CommonService.Ini().GetDataTable(dbProc);
        }

        public List<BAOBIAODY> GetAllByuser(int wtype, int type, int userId)
        {
            dbProc.Init("P_SearchReportByUser");
            dbProc.AddParameter("V_WTYPE", wtype);
            dbProc.AddParameter("V_TYPE", type);
            dbProc.AddParameter("V_USERID", userId);
            dbProc.AddOracleCursor();
            return CommonService.Ini().GetList<BAOBIAODY>(dbProc);
        }
    }
    
}